package edu.scau.divineplace.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import edu.scau.divineplace.entity.query.PageQuery;
import edu.scau.divineplace.entity.vo.FavoriteContentVO;
import edu.scau.divineplace.mapper.FavoriteServiceMapper;
import edu.scau.divineplace.util.PageQueryUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: x1aolone
 * @Date: 2020/12/11 15:48
 */
@Service
public class FavoriteService {

    @Autowired
    private ImportMapperService importMapperService;

    @Autowired
    private FavoriteServiceMapper favoriteServiceMapper;

    /**
     * 通过用户id、收藏类型获取该用户收藏的内容列表（人物除外）
     * @param userId
     * @param favoriteType FavoriteTypeEnum 想看 再看 看过
     * @param pageQuery
     * @return
     */
    public List<FavoriteContentVO> listFavoriteContentExpectRole(Long userId, Integer favoriteType, PageQuery pageQuery) {
        PageQueryUtil.fillAllIfAbsent(pageQuery);
        // 需要返回ContentBasicInformationDO、收藏类型（想看 在看 看过）、 收藏日期、总评分&评分人数
        Page<FavoriteContentVO> favoritePage = new Page<>(pageQuery.getCurrentPage(), pageQuery.getPageSize());
        List<FavoriteContentVO> list = favoriteServiceMapper.selectFavoriteContentExpectRole(favoritePage, userId, favoriteType)
                        .getRecords();
        return list;
    }

    /**
     * 通过用户id、是否真实人物获取该用户收藏的人物列表
     * @param userId
     * @param isReal
     * @param currentPage
     * @param pageSize
     * @return
     */
    public List<FavoriteContentVO> listFavoriteRole(Long userId, Integer isReal, Integer currentPage, Integer pageSize) {
        if (currentPage == null) {
            currentPage = -1;
        }
        if (pageSize == null) {
            pageSize = -1;
        }
        Page<FavoriteContentVO> favoritePage = new Page<>(currentPage, pageSize);
        List<FavoriteContentVO> list = favoriteServiceMapper.selectFavoriteRole(favoritePage, userId, isReal)
                .getRecords();
        return list;
    }

}
